<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
$setting = $this->plugin_setting('basic');
set_html('title','注册系统');
if($_RQ['op']=='get'){
	$item =array();
	$return['set']=$setting;
	$item['lat_lng']=$item['lat_lng']?json_decode($item['lat_lng'],true):'';
	$item['codeimg']=$item['codeimg']?json_decode($item['codeimg'],true):array();
	$item['addressinfo']=array('address'=>$item['address'],'lat_lng'=>$item['lat_lng']);
	$item['zhaoshangid']=intval($_RQ['zhaoshangid']);
	$item['upass']='';
	$return['roles_type']=$this->roles_type;
	$item['role_id']=2;
	$return['item']=$item;
	$return['set']['regbg']=tomedia($return['set']['regbg']);
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if(!$postdata['password']){
		exi('请填写用户名','error');
	}
	if(!$postdata['check']){
		exi('请先阅读协议！','error');
	}
	if($postdata['role_id']==1){
		$tablename='jy_baobiao_project_user';
	}
	if($postdata['role_id']==2){
		$tablename='jy_baobiao_project_cuser';
	}
	$data=array_fields(array('name','username','mobile','cname','cimage','email','address','desc','zz_file'),$postdata);
	$data['createtime']=time();
	$data['status']=1;
	if($postdata['password']){
		$data['password']=base64_encode($postdata['password']);
	}
	$log=pdo_get($tablename,array('uniacid'=>$_SESSION['uniacid'],'username'=>$postdata['username']));
	if($log){
		exi('用户名已被注册','error');
	}
	$data['uniacid']=$_SESSION['uniacid'];
	if(!$setting['isshenhe']){
		$status=1;
	}elseif($setting['isshenhe']==1){
		$status=0;
	}elseif($setting['isshenhe']==2){
		$status=0;
	}else{
		$status=1;
	}
	$data['status']=$status;
	pdo_insert($tablename,$data);
	$jigouid=pdo_insertid();
	do{
		$username='user_'.random(10);
	}while(pdo_getcolumn('core_members',array('uniacid'=>$_SESSION['uniacid'],'username'=>$username),'id'));
	$member=array('username'=>$username,'password'=>trim($postdata['password']));
	$uid=model('core/member')->register($member);
	pdo_update($tablename,array('mid'=>$uid),array('id'=>$jigouid));
	if(!$status){
		exi('已申请,请等待审核','','jy_baobiao/index/');
	}else{
		exi('注册成功，请登录！','','jy_baobiao/gongsi.login/');
	}
}
?>